package com.yeyuanqi.dao;

import com.yeyuanqi.model.domain.Comment;
import com.yeyuanqi.model.domain.CommentCount;
import com.yeyuanqi.vo.CountVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper {
    // 分页展示某个文章的评论
    @Select("SELECT * FROM t_comment WHERE article_id=#{aid} ORDER BY id DESC")
    public List<Comment> selectCommentWithPage(Integer aid);

    //查询所有评论
    @Select("SELECT * FROM t_comment ORDER BY id DESC")
    public List<Comment> selectCommentAll();

    // 后台查询最新几条评论
    @Select("SELECT * FROM t_comment ORDER BY id DESC")
    public List<Comment> selectNewComment();

    // 发表评论
    @Insert("INSERT INTO t_comment (article_id,created,author,ip,content)" +
            " VALUES (#{articleId}, #{created},#{author},#{ip},#{content})")
    public void pushComment(Comment comment);

    // 站点服务统计，统计评论数量
    @Select("SELECT COUNT(1) FROM t_comment")
    public Integer countComment();

    // 通过文章id删除评论信息
    @Delete("DELETE FROM t_comment WHERE article_id=#{aid}")
    public void deleteCommentWithId(Integer aid);

    /**
     * 通过文章id删除评论信息
     * @param aid
     */
    @Delete("delete from t_comment where article_id =#{aid}")
    void delCommentByAid(Integer aid);

    /**
     * 通过评论id删除评论信息
     * @param id
     */
    @Delete("delete from t_comment where id =#{id}")
    void delCommentById(Integer id);

    //查询文章的评论数量
    @Select("select article_id as id,count(id) as valuee from t_comment GROUP BY article_id")
    public List<CommentCount> selectCommentCount();
}

